#!/bin/sh
#This script used for install openvpn-client for linux system
#Written by Wesley,Zhang  2017/09/15 

yum install openvpn expect -y
status1=`dpkg -l |grep openvpn`
status2=`dpkg -l |grep expect`

if [[ ! $status1 ]];then
    echo "openvpn未安装成功，请更新yum源。"
else
    echo "openvpn已安装。"
fi

if [[ ! $status2 ]];then
    echo "expect未安装成功，请更新yum源。"
else
    echo "expect已安装。"
fi

linux=`cat /etc/os-release`
if [[ $linux =~ "7" ]]; then
    if [ -d /etc/openvpn/client ]; then
        /usr/bin/cp bonc_shanxi.ovpn /etc/openvpn/client 
        echo "配置文件拷贝完毕，请使用命令\"./start_vpn.sh 用户名 密码\"运行VPN。"
    else
        echo "配置目录出错，请检查openvpn是否安装成功。"
    fi
elif [[ $linux =~ "6" ]]; then
    if [ -d /etc/openvpn ]; then
        mkdir -p /etc/openvpn/client
        /bin/cp bonc_shanxi.ovpn /etc/openvpn/client
        echo "配置文件拷贝完毕，请使用命令\"./start_vpn.sh 用户名 密码\"运行VPN。"
    else
        echo "配置目录出错，请检查openvpn是否安装成功。"
    fi
fi
